# from PreTest import *
from pyecharts import options as opts
from pyecharts.render import make_snapshot
from snapshot_phantomjs import snapshot

from pyecharts.charts import Gauge



def gauge_chart() -> Gauge:
    # ********* Begin *********#
    minOne = 0.123
    gauge = (
        Gauge()
        .add("业务指标",[("完成率", 0.815206*100)],radius="50%",split_number=5,
        axisline_opts=opts.AxisLineOpts(
            linestyle_opts=opts.LineStyleOpts(
                color=[(0.3, "#67e0e3"), (0.7, "#37a2da"), (1, "#fd666d")], width=30)
        ),
        detail_label_opts=opts.LabelOpts(formatter="{value}")
    )
            # ------------------------------------------------------------
            .add("业务指标", [("完成率", (minOne*100))], radius="50%", split_number=5,
                 axisline_opts=opts.AxisLineOpts(
                     linestyle_opts=opts.LineStyleOpts(
                         color=[(0.3, "#67e0e3"), (0.7, "#37a2da"), (1, "#fd666d")], width=30)
                 ),
                 detail_label_opts=opts.LabelOpts(formatter="{value}")
                 )
            # ------------------------------------------------------------
            .add("业务指标", [("完成率", 0.385206 * 100)], radius="50%", split_number=5,
                 axisline_opts=opts.AxisLineOpts(
                     linestyle_opts=opts.LineStyleOpts(
                         color=[(0.3, "#67e0e3"), (0.7, "#37a2da"), (1, "#fd666d")], width=30)
                 ),
                 detail_label_opts=opts.LabelOpts(formatter="{value}")
                 )

    .set_global_opts(
        title_opts=opts.TitleOpts(title="Gauge-分割段数-Label"),
        legend_opts=opts.LegendOpts(is_show=False))
    )
    # ********** End **********#
    return gauge

make_snapshot(snapshot, gauge_chart().render("仪表图.html"), 'student_answer.png') # 输出图片
# make_snapshot(snapshot, gauge_split_radius().render(), "StandardAnswer/task3/standard_answer_3.png")
